import Vue from 'vue'
import vuex from 'vuex'
Vue.use(vuex);

export default new vuex.Store({
    state:{
       
    },
    mutations: {
        setLoginData (state) {
          //获取登陆信息
          state.classlist=JSON.parse('[{"id":1,"class_name":"1班","start_year":2018,"type":"1","student_num":20},{"id":2,"class_name":"2班","start_year":2018,"type":"1","student_num":10},{"id":4,"class_name":"1班","start_year":2016,"type":"1","student_num":0},{"id":6,"class_name":"3班","start_year":2018,"type":"1","student_num":8}]');
          state.info=data.JSON.parse('{"user_id":1,"user_name":"管理员老师","is_first":0}');
            state.class_data=JSON.parse('{"id":1,"class_name":"1班","start_year":2018,"type":"1","student_num":20}');


        },
        getLoginData(state){
           let token = JSON.parse(localStorage.getItem('token'));
           let timestamp=Math.round(new Date() / 1000);
           let auth="32131233";
            if (token) {           
                state.classlist=JSON.parse(localStorage.getItem('classlist'));
                state.info=JSON.parse(localStorage.getItem('info'));
                state.class_data=localStorage.getItem('class_data')?JSON.parse(localStorage.getItem('class_data')):[];
                state.token=token;
                state.Authorization=`token="${token.token}",timestamp="${timestamp}",auth="${auth}"`;
            } else {
                state.token=false
            }
        
        },
        saveClassId(state,data){
            state.class_data=data;
            localStorage.setItem('class_data', JSON.stringify(data));
        }
        
      }
})